package com.gonsin.ta.example.controllers;

import com.gonsin.base.ResponseResult;
import com.gonsin.base.exceptions.MyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class BaseController {

    @ExceptionHandler({MyException.class})
    @ResponseBody
    public ResponseResult<Void> handleMyException(MyException e) {
        log.error(e.toString(), e);
        return ResponseResult.simpleResult(500, e.getMessage());
    }
}
